package com.yanqu.road.server.manager.activity.snowgarden.service;

import com.google.protobuf.AbstractMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.pb.activity.ServerMallBuyProto;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.server.command.ICrossServiceCommand;
import com.yanqu.road.server.manager.activity.snowgarden.CrossActivityMallDayBuyMgr;

import java.util.concurrent.CompletableFuture;

public class CrossMallBuyAddServiceCmd implements ICrossServiceCommand {
    @Override
    public CompletableFuture<AbstractMessage.Builder<?>> execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        CompletableFuture<AbstractMessage.Builder<?>> completableFuture = new CompletableFuture<>();
        ServerMallBuyProto.ServerMallBuyToCrossSyncMsg syncMsg = ServerMallBuyProto.ServerMallBuyToCrossSyncMsg.parseFrom(request.getDataBytes());
        for (ServerMallBuyProto.DayBuyDataTemp temp : syncMsg.getServerBuyDataList()) {
            CrossActivityMallDayBuyMgr.updateServerMallBuy(syncMsg.getActivityId(), request.getRawServerId(), temp.getDay(), temp.getMallId(), temp.getNewCount());
        }
        ServerMallBuyProto.ServerMallBuyToCrossRespMsg.Builder respMsg = ServerMallBuyProto.ServerMallBuyToCrossRespMsg.newBuilder();
        respMsg.setActivityId(syncMsg.getActivityId());
        completableFuture.complete(respMsg);
        return completableFuture;
    }
}
